﻿using Dal;
using MD5Hash;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BLL
{
    public class MemberBll
    {
        public MemberBll(MemberDal dal)
        {
            Dal = dal;
        }

        public MemberDal Dal { get; }

        public int AddMember(Member member)
        {
            try
            {
                member.Pwd=member.Pwd.GetMD5();
                int res = Dal.GetMemberPhone(member.Phone);
                if(res>0)
                {
                    return -1;

                }
                else
                {
                    int add=Dal.AddMember(member);
                    if(add>0)
                    {
                        return 1;
                    }
                    else
                    {
                        return -2;
                    }
                }
                   
            }
            catch (Exception)
            {

                throw;
            }
        }

        public List<Member> GetMembers(string? phone = "", string? name = "", DateTime? date1 = null, DateTime? date2 = null)
        {
            List<Member> list = Dal.GetMembers(phone, name, date1,date2);
           
            return list;
        }
    }
}
